#include <managers.h>

// Variables
//Window
SDL_Window* gWindow = NULL;
//OpenGL context
SDL_GLContext gContext;
//Graphics program
GLuint ProgramID = 0;

//Screen dimension constants
int SCREEN_WIDTH = 640;
int SCREEN_HEIGHT = 480;




// Main manager
MainManager::MainManager()
{
	//
}

MainManager::~MainManager()
{
	//
}

int MainManager::startUp()
{

	//Start up SDL and create window
	if( !initSDL() )
	{
		printf( "Failed to initialize!\n" );
		return -1;
	}
}

void MainManager::shutDown()
{
	// shut down the manager
}

// Resource manager
ResourceManager::ResourceManager()
{
	//
}

ResourceManager::~ResourceManager()
{
	//
}

void ResourceManager::startUp()
{
	// start up the manager
}

void ResourceManager::shutDown()
{
	// shut down the manager
}


// Memory manager
MemoryManager::MemoryManager()
{
	//
}

MemoryManager::~MemoryManager()
{
	//
}

void MemoryManager::startUp()
{
	// start up the manager
}

void MemoryManager::shutDown()
{
	// shut down the manager
}

// Render manager
RenderManager::RenderManager()
{
	//
}

RenderManager::~RenderManager()
{
	//
}

void RenderManager::startUp()
{
	// start up the manager
}

void RenderManager::shutDown()
{
	// shut down the manager
}

// File system manager
FileSystemManager::FileSystemManager()
{
	//
}

FileSystemManager::~FileSystemManager()
{
	//
}

void FileSystemManager::startUp()
{
	// start up the manager
}

void FileSystemManager::shutDown()
{
	// shut down the manager
}


// Video manager
VideoManager::VideoManager()
{
	//
}

VideoManager::~VideoManager()
{
	//
}

void VideoManager::startUp()
{
	// start up the manager
}

void VideoManager::shutDown()
{
	// shut down the manager
}

// Texture manager
TextureManager::TextureManager()
{
	//
}

TextureManager::~TextureManager()
{
	//
}

void TextureManager::startUp()
{
	// start up the manager
}

void TextureManager::shutDown()
{
	// shut down the manager
}

// Animation manager
AnimationManager::AnimationManager()
{
	//
}

AnimationManager::~AnimationManager()
{
	//
}

void AnimationManager::startUp()
{
	// start up the manager
}

void AnimationManager::shutDown()
{
	// shut down the manager
}

// Physics manager
PhyiscsManager::PhyiscsManager()
{
	//
}

PhyiscsManager::~PhyiscsManager()
{
	//
}

void PhyiscsManager::startUp()
{
	// start up the manager
}

void PhyiscsManager::shutDown()
{
	// shut down the manager
}

// Initializes SDL and openGL
bool initSDL()
{

	//Initialize SDL
	if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
	{
		printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
		return -1;
	}

	//Use OpenGL 3.3 core
	SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 3 );
	SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 3 );
	SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );

	//Create window
	gWindow = SDL_CreateWindow( "Presence", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN );
	if( gWindow == NULL )
	{
		printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
		return -1;
	}

	//Create context
	gContext = SDL_GL_CreateContext( gWindow );
	if( gContext == NULL )
	{
		printf( "OpenGL context could not be created! SDL Error: %s\n", SDL_GetError() );
		return -1;
	}

	//Initialize GLEW
	glewExperimental = GL_TRUE; 
	GLenum glewError = glewInit();
	if( glewError != GLEW_OK )
	{
		printf( "Error initializing GLEW! %s\n", glewGetErrorString( glewError ) );
		return -1;
	}

	//Use Vsync
	if( SDL_GL_SetSwapInterval( 1 ) < 0 )
	{
		printf( "Warning: Unable to set VSync! SDL Error: %s\n", SDL_GetError() );
		return -1;
	}

	//Initialize OpenGL
	if( !initGL() )
	{
		printf( "Unable to initialize OpenGL!\n" );
		return -1;
	}

	//All is good
	return 0;

}

bool initGL()
{
	//Create vertex shader
	GLuint vertexShader = glCreateShader( GL_VERTEX_SHADER );

	//Generate program
	ProgramID = glCreateProgram();

	//All is good
	return 0;
}